Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SK2] Add Configuration.with(storeKitVersion:) to select the version of StoreKit to use #3487

Merged
merged 23 commits into from
Dec 20, 2023

Conversation

MarkVillacampa
Copy link
Member

@MarkVillacampa MarkVillacampa commented Dec 4, 2023

This PR introduces a new configuration option to select the StoreKit version to use.

It supersedes the deprecated .with(usesStoreKit2IfAvailable: true) and the internal usesStoreKit2JWS configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where applicable.

Example usage:

Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()

@MarkVillacampa MarkVillacampa added the pr:feat A new feature label Dec 4, 2023
Sources/Misc/StoreKitVersion.swift Show resolved Hide resolved
}

extension StoreKitVersion {
var versionString: String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: spacing here


extension StoreKitVersion {
var versionString: String {
if isStoreKit2EnabledAndAvailable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit self:

Suggested change
if isStoreKit2EnabledAndAvailable {
if self.isStoreKit2EnabledAndAvailable {


@testable import RevenueCat

class StoreKitVersionTests: TestCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

@@ -12,6 +12,7 @@
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Storefront" : "USA",
"X-StoreKit-Version" : "1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a better header than X-StoreKit2-Enabled 👍🏻

///
/// ### Related Symbols
/// - ``StoreKitVersion``
@objc public func with(storeKitVersion version: StoreKitVersion) -> Builder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started doing this for #3066 but ended up removing it. I think it's a better API 👍🏻

@NachoSoto
Copy link
Contributor

Looks good in general, but I want to discuss the duplicate flag.

@NachoSoto
Copy link
Contributor

Let's print the configured SK version on SDK initialization too: https://github.com/RevenueCat/purchases-ios/blob/main/Sources/Purchasing/Purchases/Purchases.swift#L556

Base automatically changed from sk2-receipt to main December 13, 2023 16:00
Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (32c63cd) 85.97% compared to head (0e854bb) 85.97%.
Report is 13 commits behind head on sk2-full-flow.

Files Patch % Lines
Sources/Misc/StoreKitVersion.swift 83.87% 5 Missing ⚠️
Sources/Purchasing/Purchases/Purchases.swift 71.42% 2 Missing ⚠️
Sources/Logging/Strings/ConfigureStrings.swift 66.66% 1 Missing ⚠️
Sources/Support/DebugUI/DebugViewModel.swift 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           sk2-full-flow    #3487      +/-   ##
=================================================
- Coverage          85.97%   85.97%   -0.01%     
=================================================
  Files                240      240              
  Lines              17494    17490       -4     
=================================================
- Hits               15041    15037       -4     
  Misses              2453     2453              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -37,6 +37,8 @@ enum ConfigureStrings {

case response_verification_mode(Signing.ResponseVerificationMode)

case storekit_version(String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This String could be anything. Better to use StoreKitVersion to make it type safe.

case storeKit2

/// Let RevenueCat use the most appropiate version of StoreKit
case `default`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making this a case, I think it would make more sense to define it like this:

extension StoreKitVersion {

  public static `default`: Self = .storeKit1

}

Since it's technically not a different version.

Then we don't need to consider it separately in all the logic, and to update it we only need to change it in one place.


extension StoreKitVersion {

var versionString: String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: putting the type of the value in the name isn't a thing anymore 😅

Maybe we can do this:

extension StoreKitVersion: CustomDebugStringConvertible {

  public var debugDescription: {
    switch self {} // Let's use a switch, so if we ever add more cases, the compiler reminds us to handle it here.
  }

}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objc throwback 🤣

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to effectiveVersion instead of using the debugDescription mechanism since it does not represent the enum value, but the effective version of StoreKit that's use despite what's configured. Added a docstring comment too.

Copy link
Contributor

@NachoSoto NachoSoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's agree one what to do with StoreKit2Setting

@@ -449,6 +447,51 @@ class PurchasesOrchestratorTests: StoreKitConfigTestCase {
expect(self.receiptFetcher.receiptDataReceivedRefreshPolicy) == .onlyIfEmpty
}

func testPurchaseSK1PackageRetriesReceiptFetchIfEnabled() async throws {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally equivalent to the removed test below, but uses SK1, since SK2 does not post receipts now.

public extension StoreKitVersion {

/// Let RevenueCat use the most appropiate version of StoreKit
static var `default` = Self.storeKit1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! This is mutable , meaning you can do

StoreKitVersion.default = .storeKit2 😬
Suggested change
static var `default` = Self.storeKit1
static let `default`: Self = .storeKit1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg good catch 😅


/// Returns a string representing the effective version of StoreKit used.
/// This can be different from the configured version if StoreKit 2 is not available on the current device.
var effectiveVersion: String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is doing 2 things:

  • Detecting the effective StoreKitVersion
  • Converting to String

I'd change this to

Suggested change
var effectiveVersion: String {
var effectiveVersion: StoreKitVersion {

Then maybe using my CustomDebugStringConvertible suggestion?


Simply remove this method call to let RevenueCat decide for you which StoreKit implementation to use.
""")
@available(*, deprecated, message: "Use .with(storeKitVersion:) to enable StoreKit 2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

@@ -548,7 +548,7 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void
}

Logger.debug(Strings.configure.debug_enabled, fileName: nil)
if systemInfo.storeKit2Setting == .enabledForCompatibleDevices {
if systemInfo.storeKitVersion.isStoreKit2EnabledAndAvailable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can remove this now that we have the generic storekit_version below?

@@ -0,0 +1,50 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, can you remove this file?

@MarkVillacampa MarkVillacampa changed the base branch from main to sk2-full-flow December 20, 2023 10:50
@MarkVillacampa MarkVillacampa merged commit f1a70e4 into sk2-full-flow Dec 20, 2023
22 checks passed
@MarkVillacampa MarkVillacampa deleted the sk2-version-configuration branch December 20, 2023 10:53
MarkVillacampa added a commit that referenced this pull request Dec 21, 2023
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Jan 11, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Jan 26, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Feb 6, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Feb 7, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
NachoSoto pushed a commit that referenced this pull request Feb 9, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
NachoSoto pushed a commit that referenced this pull request Feb 12, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
NachoSoto pushed a commit that referenced this pull request Feb 12, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
NachoSoto pushed a commit that referenced this pull request Feb 14, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Feb 21, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
joshdholtz pushed a commit that referenced this pull request Feb 23, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Mar 6, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Mar 6, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
MarkVillacampa added a commit that referenced this pull request Apr 9, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
fire-at-will pushed a commit that referenced this pull request Apr 15, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
fire-at-will pushed a commit that referenced this pull request May 13, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
fire-at-will pushed a commit that referenced this pull request Jun 24, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
fire-at-will pushed a commit that referenced this pull request Jun 28, 2024
…n of StoreKit to use (#3487)

This PR introduces a new configuration option to select the StoreKit
version to use.

It supersedes the deprecated `.with(usesStoreKit2IfAvailable: true)` and
the internal `usesStoreKit2JWS` configuration options.

Uses JWS tokens instead of SK1 receipts when in StoreKit 2 mode where
applicable.

Example usage:
```swift
Purchases.configure(
            with: .builder(withAPIKey: apiKey)
                .with(storeKitVersion: .storeKit2)
                .build()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants